﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UniLua;
using System;

public class Card : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {

    public LuaCard hCard { get; set; }

    public Text Cost;
    public Text Type;
    public Text Name;
    public Text Desc;
    public Image Img;

    public void SetCardInfo(LuaCard c)
    {
        hCard = c;
        Cost.text = c.Cost.ToString();
        Type.text = c.Type;
        Name.text = c.Name;
        Desc.text = c.Desc;
    }

    public event Action<Vector2> OnDragStarted = null;
    Vector2 startPos;
    public void OnBeginDrag(PointerEventData eventData)
    {
        startPos = eventData.position;
        if (OnDragStarted != null)
            OnDragStarted(startPos);
    }

    public event Action<LuaCard, Vector2, Vector2> OnDragging = null;
    public void OnDrag(PointerEventData eventData)
    {
        if (OnDragging != null)
            OnDragging(hCard, startPos,
            eventData.position);
    }

    public event Action<LuaCard, Vector2> OnDragEnded = null;
    public void OnEndDrag(PointerEventData eventData)
    {
        if (OnDragEnded != null)
            OnDragEnded(hCard, eventData.position);
    }
}
